package com.data.modules.online.cgform.controller;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.data.common.api.vo.Result;
import com.data.common.aspect.annotation.AutoLog;
import com.data.common.aspect.annotation.OnlineAuth;
import com.data.common.aspect.annotation.PermissionData;
import com.data.common.constant.enums.ModuleType;
import com.data.common.exception.BootException;
import com.data.common.system.api.ISysBaseAPI;
import com.data.common.system.vo.DictModel;
import com.data.common.system.vo.LoginUser;
import com.data.common.util.BrowserUtils;
import com.data.common.util.SpringContextUtils;
import com.data.common.util.TokenUtils;
import com.data.common.util.ConvertUtils;
import com.data.modules.online.auth.service.IOnlAuthPageService;
import com.data.modules.online.cgform.converter.ConvertUtil;
import com.data.modules.online.cgform.entity.OnlCgformField;
import com.data.modules.online.cgform.entity.OnlCgformHead;
import com.data.modules.online.cgform.model.OnlCgformModel;
import com.data.modules.online.cgform.model.OnlComplexModel;
import com.data.modules.online.cgform.model.OnlGenerateModel;
import com.data.modules.online.cgform.constant.LinkDown;
import com.data.modules.online.cgform.service.*;
import com.data.modules.online.cgform.util.CgFormExcelHandler;
import com.data.modules.online.cgform.util.CgformUtil;
import com.data.modules.online.cgform.util.GenerateCodeFileToZip;
import com.data.modules.online.cgform.util.OnlFormShowType;
import com.data.modules.online.config.exception.BusinessException;
import com.data.modules.online.config.exception.DBException;
import com.data.modules.online.config.executor.DbTableUtil;
import com.google.common.collect.Lists;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 *  onLine表单开发 功能控制器
 */
@Slf4j
@SuppressWarnings("ALL")
@Api(tags = "onlCgformApiController")
@RequestMapping("/online/cgform/api")
@RestController
public class OnlCgformApiController {
    @Autowired
    private IOnlAuthPageService onlAuthPageService;
    @Autowired
    private IOnlCgformFieldService onlCgformFieldService;
    @Autowired
    private IOnlCgformHeadService onlCgformHeadService;
    @Autowired
    private IOnlCgformSqlService onlCgformSqlService;
    @Autowired
    IOnlineJoinQueryService onlineJoinQueryService;
    @Autowired
    private IOnlineService onlineService;
    @Autowired
    private ISysBaseAPI sysBaseAPI;
    @Value("${databoot.path.upload:}")
    private String upLoadPath;
    @Value("${databoot.uploadType:}")
    private String uploadType;

    private static /* synthetic */ java.lang.Object m35a(java.lang.invoke.SerializedLambda r4) {
        /*
        // Method dump skipped, instructions count: 1012
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.m35a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

    /** onLine表单开发 新增
     * @param aVar
     * @return
     */
    @ApiOperation("onLine表单开发 新增")
    @PostMapping({"/addAll"})
    public Result<?> addAll(@RequestBody OnlCgformModel aVar) {
        try {
            String tableName = aVar.getHead().getTableName();
            if (DbTableUtil.checkTableIsExist(tableName).booleanValue()) {
                return Result.error("数据库表[" + tableName + "]已存在,请从数据库导入表单");
            }
            return this.onlCgformHeadService.addAll(aVar);
        } catch (Exception e) {
            log.error("OnlCgformApiController.addAll()发生异常：" + e.getMessage(), e);
            return Result.error("操作失败");
        }
    }

    @CacheEvict(allEntries = true, beforeInvocation = true, value = {"sys:cache:online:list", "sys:cache:online:form"})
    @PutMapping({"/editAll"})
    public Result<?> editAll(@RequestBody OnlCgformModel aVar) {
        try {
            return this.onlCgformHeadService.editAll(aVar);
        } catch (Exception e) {
            log.error("OnlCgformApiController.editAll()发生异常：" + e.getMessage(), e);
            return Result.error("操作失败");
        }
    }

    /** 查询 表字段 java列
     * @param code
     * @return
     */
    @ApiOperation("查询 表字段 java列")
    @OnlineAuth("getColumns")
    @AutoLog(module = ModuleType.ONLINE, operateType = 1, value = "online列表加载")
    @GetMapping({"/getColumns/{code}"})
    public Result<OnlComplexModel> getColumns(@PathVariable("code") String code) {
        Result<OnlComplexModel> result = new Result<>();
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(code);
        if (onlCgformHead == null) {
            result.error500("实体不存在");
            return result;
        }
        OnlComplexModel queryOnlineConfig = this.onlineService.queryOnlineConfig(onlCgformHead, ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername());
        queryOnlineConfig.setIsDesForm(onlCgformHead.getIsDesForm());
        queryOnlineConfig.setDesFormCode(onlCgformHead.getDesFormCode());
        result.setResult(queryOnlineConfig);
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

    /** 查询表 分页列表
     * @param code
     * @param httpServletRequest
     * @return
     */
    @ApiOperation("查询表 分页列表")
    @OnlineAuth("getData")
    @AutoLog(module = ModuleType.ONLINE, operateType = 1, value = "online列表数据查询")
    @PermissionData
    @GetMapping({"/getData/{code}"})
    public Result<Map<String, Object>> getDataByCode(@PathVariable("code") String code, HttpServletRequest httpServletRequest) {
        Map<String, Object> queryAutolistPage;
        Result<Map<String, Object>> result = new Result<>();
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(code);
        if (onlCgformHead == null) {
            result.error500("实体不存在");
            return result;
        }
        try {
            Map<String, Object> a = CgformUtil.m243a(httpServletRequest);
            if (CgformUtil.m258a(onlCgformHead)) {
                queryAutolistPage = this.onlineJoinQueryService.pageList(onlCgformHead, a);
            } else {
                queryAutolistPage = this.onlCgformFieldService.queryAutolistPage(onlCgformHead, a, null);
            }
            m39a(onlCgformHead, queryAutolistPage);
            result.setResult(queryAutolistPage);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("数据库查询失败，" + e.getMessage());
        }
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

    /** 查询 表结构
     * @param code
     * @param httpServletRequest
     * @return
     */
    @ApiOperation("查询 表结构")
    @OnlineAuth("getFormItem")
    @AutoLog(module = ModuleType.ONLINE, operateType = 1, value = "online表单加载")
    @GetMapping({"/getFormItem/{code}"})
    public Result<?> getFormItemByCode(@PathVariable("code") String code, HttpServletRequest httpServletRequest) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(code);
        if (onlCgformHead == null) {
            Result.error("表不存在");
        }
        JSONObject rs = CgformUtil.m263b(this.onlineService.queryOnlineFormItem(onlCgformHead, ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername()));
        Result<com.alibaba.fastjson.JSONObject> result = new Result<>();
        result.setResult(rs);
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

public Result<?> mo305a(java.lang.String r5, java.lang.String r6) {
        /*
            r4 = this;
            com.data.common.api.vo.Result r2 = new com.data.common.api.vo.Result
            r2.<init>()
            com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper r0 = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
            void r1 = r0.<init>()
            r0.eq(r1, r5)
            org.jeecg.modules.online.cgform.service.IOnlCgformHeadService r1 = r4.onlCgformHeadService
            java.lang.Object r0 = r1.getOne(r0)
            org.jeecg.modules.online.cgform.entity.OnlCgformHead r0 = (org.jeecg.modules.online.cgform.entity.OnlCgformHead) r0
            if (r0 != 0) goto L_0x0020
            java.lang.String r1 = "表不存在"
            com.data.common.api.vo.Result.error(r1)
        L_0x0020:
            org.apache.shiro.subject.Subject r1 = org.apache.shiro.SecurityUtils.getSubject()
            java.lang.Object r1 = r1.getPrincipal()
            com.data.common.system.vo.LoginUser r1 = (com.data.common.system.vo.LoginUser) r1
            org.jeecg.modules.online.cgform.service.IOnlineService r3 = r4.onlineService
            java.lang.String r1 = r1.getUsername()
            com.alibaba.fastjson.JSONObject r0 = r3.queryFlowOnlineFormItem(r0, r1, r6)
            com.alibaba.fastjson.JSONObject r0 = org.jeecg.modules.online.cgform.util.CgformUtil.m263b(r0)
            r2.setResult(r0)
            r2.setOnlTable(r5)
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.mo305a(java.lang.String, java.lang.String):com.data.common.api.vo.Result");
    }

    @OnlineAuth("getEnhanceJs")
    @GetMapping({"/getEnhanceJs/{code}"})
    public Result<?> getEnhanceJsBtCode(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        return Result.ok(this.onlineService.queryEnahcneJsString(str, CgformUtil.f276al));
    }

    @AutoLog(operateType = 1, value = "online表单数据查询")
    @GetMapping({"/form/{code}/{id}"})
    public Result<?> formByCodeAndId(@PathVariable("code") String str, @PathVariable("id") String str2) {
        try {
            return Result.ok(CgformUtil.m242a(this.onlCgformHeadService.queryManyFormData(str, str2)));
        } catch (Exception e) {
            log.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @GetMapping({"/subform/{table}/{mainId}"})
    public Result<?> subformForTable(@PathVariable("table") String str, @PathVariable("mainId") String str2) {
        try {
            return Result.ok(CgformUtil.m242a(this.onlCgformHeadService.querySubFormData(str, str2)));
        } catch (Exception e) {
            log.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @GetMapping({"/subform/list/{table}/{mainId}"})
    public Result<?> listByTale(@PathVariable("table") String str, @PathVariable("mainId") String str2) {
        try {
            return Result.ok(this.onlCgformHeadService.queryManySubFormData(str, str2));
        } catch (Exception e) {
            log.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

public Result<?> mo324e(java.lang.String r5, java.lang.String r6) {
        /*
        // Method dump skipped, instructions count: 122
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.mo324e(java.lang.String, java.lang.String):com.data.common.api.vo.Result");
    }

    @OnlineAuth(CgformUtil.f276al)
    @PostMapping({"/form/{code}"})
    @AutoLog(module = ModuleType.ONLINE, operateType = 2, value = "online新增数据")
    public Result<String> addFormByCode(@PathVariable("code") String str, @RequestBody JSONObject jSONObject, HttpServletRequest httpServletRequest) {
        Result<String> result = new Result<>();
        try {
            String a = CgformUtil.getId();
            jSONObject.put("id", a);
            String saveManyFormData = this.onlCgformHeadService.saveManyFormData(str, jSONObject, TokenUtils.getTokenByRequest(httpServletRequest));
            result.setSuccess(true);
            result.setResult(a);
            result.setOnlTable(saveManyFormData);
            result.setMessage("添加成功!");
        } catch (Exception e) {
            log.error("OnlCgformApiController.formAdd()发生异常：", e);
            result.setSuccess(false);
            result.setMessage("保存失败，" + CgformUtil.m224a(e));
        }
        return result;
    }

    @OnlineAuth(CgformUtil.f276al)
    @AutoLog(module = ModuleType.ONLINE, operateType = 3, value = "online修改数据")
    @PutMapping({"/form/{code}"})
    public Result<?> updateFormCode(@PathVariable("code") String str, @RequestBody JSONObject jSONObject) {
        try {
            String editManyFormData = this.onlCgformHeadService.editManyFormData(str, jSONObject);
            Result<?> ok = Result.ok("修改成功！");
            ok.setOnlTable(editManyFormData);
            return ok;
        } catch (Exception e) {
            log.error("OnlCgformApiController.formEdit()发生异常：" + e.getMessage(), e);
            return Result.error("修改失败，" + CgformUtil.m224a(e));
        }
    }

    @OnlineAuth(CgformUtil.f276al)
    @AutoLog(module = ModuleType.ONLINE, operateType = 4, value = "online删除数据")
    @DeleteMapping({"/form/{code}/{id}"})
    public Result<?> deleteFormByCode(@PathVariable("code") String str, @PathVariable("id") String str2) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            return Result.error("实体不存在");
        }
        String str3 = "";
        try {
            if ("Y".equals(onlCgformHead.getIsTree())) {
                str2 = this.onlCgformFieldService.queryTreeChildIds(onlCgformHead, str2);
                str3 = this.onlCgformFieldService.queryTreePids(onlCgformHead, str2);
            }
            if (str2.indexOf(CgformUtil.f231E) > 0) {
                if (onlCgformHead.getTableType().intValue() == 2) {
                    this.onlCgformFieldService.deleteAutoListMainAndSub(onlCgformHead, str2);
                } else {
                    this.onlCgformFieldService.deleteAutoListById(onlCgformHead.getTableName(), str2);
                }
                if ("Y".equals(onlCgformHead.getIsTree())) {
                    String tableName = onlCgformHead.getTableName();
                    String treeIdField = onlCgformHead.getTreeIdField();
                    String[] split = str3.split(CgformUtil.f231E);
                    for (String str4 : split) {
                        this.onlCgformFieldService.updateTreeNodeNoChild(tableName, treeIdField, str4);
                    }
                }
            } else {
                this.onlCgformHeadService.deleteOneTableInfo(str, str2);
            }
            if (ConvertUtils.isNotEmpty(onlCgformHead.getIsDesForm()) && "1".equals(onlCgformHead.getIsDesForm())) {
                this.onlCgformFieldService.deleteAutoList("design_form_data", "online_form_data_id", str2);
            }
            Result<?> ok = Result.ok("删除成功!");
            ok.setOnlTable(onlCgformHead.getTableName());
            return ok;
        } catch (Exception e) {
            log.error("OnlCgformApiController.formEdit()发生异常：" + e.getMessage(), e);
            return Result.error("删除失败," + e.getMessage());
        }
    }

    @DeleteMapping({"/formByCode/{code}/{id}"})
    @AutoLog(module = ModuleType.ONLINE, operateType = 4, value = "online删除数据")
    public Result<?> deleteFormByCodeAndId(@PathVariable("code") String str, @PathVariable("id") String str2) {
        try {
            String deleteDataByCode = this.onlCgformHeadService.deleteDataByCode(str, str2);
            Result<?> OK = Result.OK("删除成功!", deleteDataByCode);
            OK.setOnlTable(deleteDataByCode);
            return OK;
        } catch (BootException e) {
            return Result.error(e.getMessage());
        }
    }

    /** 查询 表详情
     * @param code
     * @return
     */
    @ApiOperation("查询 表详情")
    @OnlineAuth("getQueryInfo")
    @GetMapping({"/getQueryInfo/{code}"})
    public Result<?> getQueryInfo(@PathVariable("code") String code) {
        try {
            return Result.ok(this.onlCgformFieldService.getAutoListQueryInfo(code));
        } catch (Exception e) {
            log.error("OnlCgformApiController.getQueryInfo()发生异常：" + e.getMessage(), e);
            return Result.error("查询失败");
        }
    }

    @PostMapping({"/doDbSynch/{code}/{synMethod}"})
    public Result<?> doDbSynchByCode(@PathVariable("code") String str, @PathVariable("synMethod") String str2) {
        try {
            System.currentTimeMillis();
            this.onlCgformHeadService.doDbSynch(str, str2);
            return Result.ok("同步数据库成功!");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("同步数据库失败，" + CgformUtil.m224a(e));
        }
    }

    @OnlineAuth("exportXls")
    @PermissionData
    @GetMapping({"/exportXls/{code}"})
    public void exportXls(@PathVariable("code") String var1, HttpServletRequest var2, HttpServletResponse var3) {
        OnlCgformHead var4 = (OnlCgformHead)this.onlCgformHeadService.getById(var1);
        if (var4 != null) {
            String var5 = var4.getTableTxt();
            String var6 = var2.getParameter("paramsStr");
            Object var7 = new HashMap();
            Object var8 = null;
            if (ConvertUtils.isNotEmpty(var6)) {
                var7 = (Map)JSONObject.parseObject(var6, Map.class);
            }

            ((Map)var7).put("pageSize", -521);
            boolean var9 = CgformUtil.a(var4);
            Map var10 = null;
            if (var9) {
                var10 = this.onlineJoinQueryService.pageList(var4, (Map)var7, true);
            } else {
                var10 = this.onlCgformFieldService.queryAutolistPage(var4, (Map)var7, (List)null);
            }

            List var11 = (List)var10.get("fieldList");
            List var12 = (List)var10.get("records");
            Object var13 = new ArrayList();
            String var14 = ((Map)var7).get("selections") == null ? null : ((Map)var7).get("selections").toString();
            List var15;
            if (ConvertUtils.isNotEmpty(var14)) {
                var15 = Arrays.asList(var14.split(","));
                List finalVar1 = var15;
                var13 = var12.stream().filter((var1x) -> {
                    Map<String, Object> tmp = (Map<String, Object>) var1x;
                    return finalVar1.contains(tmp.get("id"));
                }).collect(Collectors.toList());
            } else {
                if (var12 == null) {
                    var12 = new ArrayList();
                }

                ((List)var13).addAll((Collection)var12);
            }
            ConvertUtil.m131a(1, (List)var13, var11);
            //org.jeecg.modules.online.cgform.converter.b.a(1, (List)var13, var11);

            try {
                this.onlCgformHeadService.executeEnhanceExport(var4, (List)var13);
            } catch (BusinessException var32) {
                log.error("导出java增强处理出错", var32.getMessage());
            }

            var15 = this.m36a(var11, "id");
            if (var4.getTableType() == 2 && ConvertUtils.isEmpty(((Map)var7).get("exportSingleOnly"))) {
                String var16 = var4.getSubTableStr();
                if (ConvertUtils.isNotEmpty(var16)) {
                    String[] var17 = var16.split(",");
                    String[] var18 = var17;
                    int var19 = var17.length;

                    for(int var20 = 0; var20 < var19; ++var20) {
                        String var21 = var18[var20];
                        this.m37a(var21, (Map)var7, (List)var13, var15);
                    }
                }
            }

            Workbook var34 = ExcelExportUtil.exportExcel(new ExportParams((String)null, var5), var15, (Collection)var13);
            ServletOutputStream var35 = null;

            try {
                var3.setContentType("application/x-msdownload;charset=utf-8");
                String var36 = BrowserUtils.checkBrowse(var2);
                String var37 = var4.getTableTxt() + "-v" + var4.getTableVersion();
                if ("MSIE".equalsIgnoreCase(var36.substring(0, 4))) {
                    var3.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(var37, "UTF-8") + ".xls");
                } else {
                    String var38 = new String(var37.getBytes("UTF-8"), "ISO8859-1");
                    var3.setHeader("content-disposition", "attachment;filename=" + var38 + ".xls");
                }

                var35 = var3.getOutputStream();
                var34.write(var35);
                var3.flushBuffer();
            } catch (Exception var31) {
                log.error("--通过流的方式获取文件异常--" + var31.getMessage(), var31);
            } finally {
                if (var35 != null) {
                    try {
                        var35.close();
                    } catch (IOException var30) {
                        log.error(var30.getMessage(), var30);
                    }
                }

            }

        }
    }

    @OnlineAuth("importXls")
    @PostMapping({"/importXls/{code}"})
    public Result<?> importXls(@PathVariable("code") String var1, HttpServletRequest var2, HttpServletResponse var3) {
        long var4 = System.currentTimeMillis();
        Result var6 = new Result();
        String var7 = "";
        String var8 = var2.getParameter("validateStatus");
        StringBuffer var9 = new StringBuffer();

        try {
            OnlCgformHead var10 = (OnlCgformHead)this.onlCgformHeadService.getById(var1);
            if (var10 == null) {
                return Result.error("数据库不存在该表记录");
            }

            LambdaQueryWrapper<OnlCgformField> var11 = new LambdaQueryWrapper<OnlCgformField>();
            var11.eq(OnlCgformField::getCgformHeadId, var1);
            List var12 = this.onlCgformFieldService.list(var11);
            String var13 = var2.getParameter("isSingleTableImport");
            List var14 = CgformUtil.m284e(var12);
            if (ConvertUtils.isEmpty(var13) && var10.getTableType() == 2 && ConvertUtils.isNotEmpty(var10.getSubTableStr())) {
                String[] var15 = var10.getSubTableStr().split(",");
                int var16 = var15.length;

                for(int var17 = 0; var17 < var16; ++var17) {
                    String var18 = var15[var17];
                    OnlCgformHead var19 = (OnlCgformHead)this.onlCgformHeadService.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var18));
                    if (var19 != null) {
                        List var20 = this.onlCgformFieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var19.getId()));
                        List var21 = CgformUtil.m268b(var20, var19.getTableTxt());
                        if (var21.size() > 0) {
                            var14.addAll(var21);
                        }
                    }
                }
            }

            JSONObject var49 = null;
            String var50 = var2.getParameter("foreignKeys");
            if (ConvertUtils.isNotEmpty(var50)) {
                var49 = JSONObject.parseObject(var50);
            }

            MultipartHttpServletRequest var51 = (MultipartHttpServletRequest)var2;
            Map var52 = var51.getFileMap();
            DataSource var53 = (DataSource) SpringContextUtils.getApplicationContext().getBean(DataSource.class);
            String var54 = DbTableUtil.m432a(var53);
            Iterator var55 = var52.entrySet().iterator();

            while(true) {
                while(var55.hasNext()) {
                    Map.Entry var22 = (Map.Entry)var55.next();
                    MultipartFile var23 = (MultipartFile)var22.getValue();
                    ImportParams var24 = new ImportParams();
                    var24.setImageList(var14);
                    var24.setDataHanlder(new CgFormExcelHandler(var12, this.upLoadPath, this.uploadType));
                    List var25 = ExcelImportUtil.importExcel(var23.getInputStream(), Map.class, var24);
                    if (var25 != null) {
                        Object var26 = "";
                        ArrayList var27 = new ArrayList();

                        Map var29;
                        for(Iterator var28 = var25.iterator(); var28.hasNext(); var29.put("$mainTable$id", var26)) {
                            var29 = (Map)var28.next();
                            boolean var30 = false;
                            Set var31 = var29.keySet();
                            HashMap var32 = new HashMap();
                            Iterator var33 = var31.iterator();

                            String var34;
                            while(var33.hasNext()) {
                                var34 = (String)var33.next();
                                if (var34.indexOf("$subTable$") == -1) {
                                    if (var34.indexOf("$mainTable$") != -1 && ConvertUtils.isNotEmpty(var29.get(var34).toString())) {
                                        var30 = true;
                                        var26 = this.mo300a(var10, var53, var54);
                                    }

                                    var32.put(var34.replace("$mainTable$", ""), var29.get(var34));
                                }
                            }

                            if (var30) {
                                var32.put("id", var26);
                                var27.add(var32);
                                var26 = var32.get("id");
                            }

                            if (var49 != null) {
                                var33 = var49.keySet().iterator();

                                while(var33.hasNext()) {
                                    var34 = (String)var33.next();
                                    System.out.println(var34 + "=" + var49.getString(var34));
                                    var32.put(var34, var49.getString(var34));
                                }
                            }
                        }

                        if (var27 == null || var27.size() == 0) {
                            var6.setSuccess(false);
                            var6.setMessage("导入失败，匹配的数据条数为零!");
                            return var6;
                        }

                        if ("1".equals(var8)) {
                            Map var57 = this.onlCgformSqlService.saveOnlineImportDataWithValidate(var10, var12, var27);
                            String var59 = (String)var57.get("error");
                            var7 = (String)var57.get("tip");
                            if (var59 != null && var59.length() > 0) {
                                var9.append(var10.getTableTxt() + "导入校验," + var7 + ",详情如下:\r\n" + var59);
                            }
                        } else {
                            this.onlCgformSqlService.saveBatchOnlineTable(var10, var12, var27);
                        }

                        if (ConvertUtils.isEmpty(var13) && var10.getTableType() == 2 && ConvertUtils.isNotEmpty(var10.getSubTableStr())) {
                            String[] var58 = var10.getSubTableStr().split(",");
                            int var60 = var58.length;

                            for(int var61 = 0; var61 < var60; ++var61) {
                                String var62 = var58[var61];
                                OnlCgformHead var63 = (OnlCgformHead)this.onlCgformHeadService.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var62));
                                if (var63 != null) {
                                    LambdaQueryWrapper<OnlCgformField> var64 = new LambdaQueryWrapper<OnlCgformField>();
                                    var64.eq(OnlCgformField::getCgformHeadId, var63.getId());
                                    List var65 = this.onlCgformFieldService.list(var64);
                                    ArrayList var35 = new ArrayList();
                                    String var36 = var63.getTableTxt();
                                    Iterator var37 = var25.iterator();

                                    while(var37.hasNext()) {
                                        Map var38 = (Map)var37.next();
                                        boolean var39 = false;
                                        HashMap var40 = new HashMap();
                                        Iterator var41 = var65.iterator();

                                        while(var41.hasNext()) {
                                            OnlCgformField var42 = (OnlCgformField)var41.next();
                                            String var43 = var42.getMainTable();
                                            String var44 = var42.getMainField();
                                            boolean var45 = var10.getTableName().equals(var43) && ConvertUtils.isNotEmpty(var44);
                                            String var46 = var36 + "_" + var42.getDbFieldTxt();
                                            if (var45) {
                                                var40.put(var42.getDbFieldName(), var38.get("$mainTable$" + var44));
                                            }

                                            Object var47 = var38.get("$subTable$" + var46);
                                            if (null != var47 && ConvertUtils.isNotEmpty(var47.toString())) {
                                                var39 = true;
                                                var40.put(var42.getDbFieldName(), var47);
                                            }
                                        }

                                        if (var39) {
                                            var40.put("id", this.mo300a(var63, var53, var54));
                                            var35.add(var40);
                                        }
                                    }

                                    if (var35.size() > 0) {
                                        if ("1".equals(var8)) {
                                            Map var66 = this.onlCgformSqlService.saveOnlineImportDataWithValidate(var63, var65, var35);
                                            String var67 = (String)var66.get("error");
                                            String var68 = (String)var66.get("tip");
                                            if (var67 != null && var67.length() > 0) {
                                                var9.append(var63.getTableTxt() + "导入校验," + var68 + ",详情如下:\r\n" + var67);
                                            }
                                        } else {
                                            this.onlCgformSqlService.saveBatchOnlineTable(var63, var65, var35);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        var7 = "识别模版数据错误";
                        log.error(var7);
                    }
                }

                var6.setSuccess(true);
                if ("1".equals(var8) && var9.length() > 0) {
                    String var56 = CgformUtil.m228a(this.upLoadPath, var10.getTableTxt(), var9);
                    var6.setResult(var56);
                    var6.setMessage(var7);
                    var6.setCode(201);
                } else {
                    var6.setMessage("导入成功!");
                }
                break;
            }
        } catch (Exception var48) {
            var6.setSuccess(false);
            var6.setMessage(var48.getMessage());
            log.error(var48.getMessage(), var48);
        }

        return var6;
    }


    @PostMapping({"/doButton"})
    public Result<?> mo301a(@RequestBody JSONObject jSONObject) {
        String string = jSONObject.getString("formId");
        String string2 = jSONObject.getString("dataId");
        String string3 = jSONObject.getString("buttonCode");
        jSONObject.getJSONObject("uiFormData");
        try {
            this.onlCgformHeadService.executeCustomerButton(string3, string, string2);
            return Result.ok("执行成功!");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("执行失败," + e.getMessage());
        }
    }

    public Object mo300a(OnlCgformHead onlCgformHead, DataSource dataSource, String str) throws SQLException, DBException {
        String idType = onlCgformHead.getIdType();
        String idSequence = onlCgformHead.getIdSequence();
        if (ConvertUtils.isNotEmpty(idType) && "UUID".equalsIgnoreCase(idType)) {
            return CgformUtil.getId();
        }
        if (!ConvertUtils.isNotEmpty(idType) || !"NATIVE".equalsIgnoreCase(idType)) {
            if (!ConvertUtils.isNotEmpty(idType) || !"SEQUENCE".equalsIgnoreCase(idType)) {
                return CgformUtil.getId();
            }
            if (ConvertUtils.isNotEmpty(str) && "oracle".equalsIgnoreCase(str)) {
                try {
                    return Long.valueOf(new OracleSequenceMaxValueIncrementer(dataSource, idSequence).nextLongValue());
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    return null;
                }
            } else if (!ConvertUtils.isNotEmpty(str) || !"postgres".equalsIgnoreCase(str)) {
                return null;
            } else {
                try {
                    return Long.valueOf(new PostgreSQLSequenceMaxValueIncrementer(dataSource, idSequence).nextLongValue());
                } catch (Exception e2) {
                    log.error(e2.getMessage(), e2);
                    return null;
                }
            }
        } else if (ConvertUtils.isNotEmpty(str) && "oracle".equalsIgnoreCase(str)) {
            try {
                return Long.valueOf(new OracleSequenceMaxValueIncrementer(dataSource, "HIBERNATE_SEQUENCE").nextLongValue());
            } catch (Exception e3) {
                log.error(e3.getMessage(), e3);
                return null;
            }
        } else if (!ConvertUtils.isNotEmpty(str) || !"postgres".equalsIgnoreCase(str)) {
            return null;
        } else {
            try {
                return Long.valueOf(new PostgreSQLSequenceMaxValueIncrementer(dataSource, "HIBERNATE_SEQUENCE").nextLongValue());
            } catch (Exception e4) {
                log.error(e4.getMessage(), e4);
                return null;
            }
        }
    }

    private void m38a(Map map, List<OnlCgformField> list) {
        List<DictModel> queryTableDictItemsByCode;
        for (OnlCgformField onlCgformField : list) {
            String dictTable = onlCgformField.getDictTable();
            String dictField = onlCgformField.getDictField();
            String dictText = onlCgformField.getDictText();
            if ((!ConvertUtils.isEmpty(dictTable) || !ConvertUtils.isEmpty(dictField)) && !CgformUtil.f239M.equals(onlCgformField.getFieldShowType())) {
                String valueOf = String.valueOf(map.get(onlCgformField.getDbFieldName()));
                if (ConvertUtils.isEmpty(dictTable)) {
                    queryTableDictItemsByCode = this.sysBaseAPI.queryDictItemsByCode(dictField);
                } else {
                    queryTableDictItemsByCode = this.sysBaseAPI.queryTableDictItemsByCode(dictTable, dictText, dictField);
                }
                for (DictModel dictModel : queryTableDictItemsByCode) {
                    if (valueOf.equals(dictModel.getText())) {
                        map.put(onlCgformField.getDbFieldName(), dictModel.getValue());
                    }
                }
            }
        }
    }

    private List<ExcelExportEntity> m36a(List<OnlCgformField> list, String str) {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            if ((str == null || !str.equals(list.get(i).getDbFieldName())) && list.get(i).getIsShowList().intValue() == 1) {
                ExcelExportEntity excelExportEntity = new ExcelExportEntity(list.get(i).getDbFieldTxt(), list.get(i).getDbFieldName());
                if ("image".equals(list.get(i).getFieldShowType())) {
                    excelExportEntity.setType(2);
                    excelExportEntity.setExportImageType(3);
                    excelExportEntity.setImageBasePath(this.upLoadPath);
                    excelExportEntity.setHeight(50.0d);
                    excelExportEntity.setWidth(60.0d);
                } else {
                    int intValue = list.get(i).getDbLength().intValue() == 0 ? 12 : list.get(i).getDbLength().intValue() > 30 ? 30 : list.get(i).getDbLength().intValue();
                    if (list.get(i).getFieldShowType().equals(OnlFormShowType.f320d)) {
                        excelExportEntity.setFormat("yyyy-MM-dd");
                    } else if (list.get(i).getFieldShowType().equals("datetime")) {
                        excelExportEntity.setFormat("yyyy-MM-dd HH:mm:ss");
                    }
                    if (intValue < 10) {
                        intValue = 10;
                    }
                    excelExportEntity.setWidth((double) intValue);
                }
                arrayList.add(excelExportEntity);
            }
        }
        return arrayList;
    }

    private void m37a(String var1, Map<String, Object> var2, List<Map<String, Object>> var3, List<ExcelExportEntity> var4) {
        OnlCgformHead var5 = (OnlCgformHead)this.onlCgformHeadService.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var1));
        LambdaQueryWrapper<OnlCgformField> var6 = new LambdaQueryWrapper<OnlCgformField>();
        var6.eq(OnlCgformField::getCgformHeadId, var5.getId());
        var6.orderByAsc(OnlCgformField::getOrderNum);
        List var7 = this.onlCgformFieldService.list(var6);
        String var8 = "";
        String var9 = "";
        Iterator var10 = var7.iterator();

        while(var10.hasNext()) {
            OnlCgformField var11 = (OnlCgformField)var10.next();
            if (ConvertUtils.isNotEmpty(var11.getMainField())) {
                var8 = var11.getMainField();
                var9 = var11.getDbFieldName();
                break;
            }
        }

        ExcelExportEntity var14 = new ExcelExportEntity(var5.getTableTxt(), var1);
        var14.setList(this.m36a(var7, "id"));
        var4.add(var14);

        for(int var15 = 0; var15 < var3.size(); ++var15) {
            var2.put(var9, ((Map)var3.get(var15)).get(var8));
            String var12 = CgformUtil.m231a(var5.getTableName(), var7, var2);
            List var13 = this.onlCgformHeadService.queryListData(var12);

            ConvertUtil.m131a(1, var13, var7);
            ((Map)var3.get(var15)).put(var1, CgformUtil.m280d(var13));
        }

    }

@GetMapping({"/checkOnlyTable"})
public com.data.common.api.vo.Result<?> mo329i(@RequestParam("tbname") java.lang.String r5, @RequestParam("id") java.lang.String r6) {
        /*
        // Method dump skipped, instructions count: 111
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.mo329i(java.lang.String, java.lang.String):com.data.common.api.vo.Result");
    }

    /** 生成代码
     * @param jSONObject
     * @return
     */
    @ApiOperation("生成代码")
    @PostMapping({"/codeGenerate"})
    public Result<?> codeGenerate(@RequestBody JSONObject jSONObject) {
        List<String> generateOneToMany;
        OnlGenerateModel onlGenerateModel = (OnlGenerateModel) JSONObject.parseObject(jSONObject.toJSONString(), OnlGenerateModel.class);
        try {
            if ("1".equals(onlGenerateModel.getJformType())) {
                generateOneToMany = this.onlCgformHeadService.generateCode(onlGenerateModel);
            } else {
                generateOneToMany = this.onlCgformHeadService.generateOneToMany(onlGenerateModel);
            }
            return Result.ok(generateOneToMany);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    private static /* synthetic */ boolean m41d(String str) {
        return str.indexOf("src/main/java") == -1 && str.indexOf("src%5Cmain%5Cjava") == -1;
    }

    /** 下载到本地
     * @param fileList
     * @param request
     * @param response
     */
    @ApiOperation("下载到本地")
    @GetMapping({"/downGenerateCode"})
    public void downGenerateCode(@RequestParam("fileList") List<String> fileList, HttpServletRequest request, HttpServletResponse response) {
        List filePaths = (List)fileList.stream().filter((file) -> {
            return file.indexOf("src/main/java") == -1 && file.indexOf("src%5Cmain%5Cjava") == -1;
        }).collect(Collectors.toList());
        if (fileList != null && (filePaths == null || filePaths.size() <= 0)) {
            String tempZipPath = "生成代码_" + System.currentTimeMillis() + ".zip";
            final String zipPath = "/opt/temp/codegenerate/" + tempZipPath;
            File zipFile = GenerateCodeFileToZip.generateFile(fileList, zipPath);
            if (zipFile.exists()) {
                response.setContentType("application/force-download");
                response.addHeader("Content-Disposition", "attachment;fileName=" + tempZipPath);
                byte[] bytes = new byte[1024];
                FileInputStream zipFileInputStream = null;
                BufferedInputStream bufferedInputStream = null;

                try {
                    zipFileInputStream = new FileInputStream(zipFile);
                    bufferedInputStream = new BufferedInputStream(zipFileInputStream);
                    ServletOutputStream outputStream = response.getOutputStream();

                    for(int i = bufferedInputStream.read(bytes); i != -1; i = bufferedInputStream.read(bytes)) {
                        outputStream.write(bytes, 0, i);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException ioException) {
                            ioException.printStackTrace();
                        }
                    }

                    if (zipFileInputStream != null) {
                        try {
                            zipFileInputStream.close();
                        } catch (IOException ioException) {
                            ioException.printStackTrace();
                        }
                    }

                    class NamelessClass_1 extends Thread {
                        NamelessClass_1() {
                        }

                        public void run() {
                            try {
                                Thread.sleep(10000L);
                                FileUtil.del(zipPath);
                            } catch (InterruptedException interruptedException) {
                                interruptedException.printStackTrace();
                            }

                        }
                    }

                    (new NamelessClass_1()).start();
                }
            }

        } else {
            log.error(" fileList 不合法！！！", fileList);
        }
    }

    @AutoLog(module = ModuleType.ONLINE, operateType = 1, value = "online列表数据查询")
    @PermissionData
    @GetMapping({"/getTreeData/{code}"})
    public Result<Map<String, Object>> mo323d(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        Result<Map<String, Object>> result = new Result<>();
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            result.error500("实体不存在");
            return result;
        }
        try {
            String tableName = onlCgformHead.getTableName();
            String treeIdField = onlCgformHead.getTreeIdField();
            String treeParentIdField = onlCgformHead.getTreeParentIdField();
            ArrayList newArrayList = Lists.newArrayList(new String[]{treeIdField, treeParentIdField});
            Map<String, Object> a = CgformUtil.m243a(httpServletRequest);
            if (a.get(treeIdField) != null) {
                a.get(treeIdField).toString();
            }
            if (a.get("hasQuery") == null || !"false".equals(a.get("hasQuery")) || a.get(treeParentIdField) != null) {
                a.put("pageSize", -521);
                a.put(treeParentIdField, a.get(treeParentIdField));
            } else {
                a.put(treeParentIdField, "0");
            }
            a.put(treeIdField, null);
            Map<String, Object> queryAutoTreeNoPage = this.onlCgformFieldService.queryAutoTreeNoPage(tableName, str, a, newArrayList, treeParentIdField);
            m39a(onlCgformHead, queryAutoTreeNoPage);
            result.setResult(queryAutoTreeNoPage);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("数据库查询失败" + e.getMessage());
        }
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

    private void m39a(OnlCgformHead onlCgformHead, Map<String, Object> map) throws BusinessException {
        this.onlCgformHeadService.executeEnhanceList(onlCgformHead, "query", (List) map.get("records"));
    }

    @PostMapping({"/crazyForm/{name}"})
    public Result<?> mo313b(@PathVariable("name") String str, @RequestBody JSONObject jSONObject) {
        Result<String> result = new Result<>();
        try {
            String a = CgformUtil.getId();
            jSONObject.put("id", a);
            this.onlCgformHeadService.addCrazyFormData(str, jSONObject);
            result.setResult(a);
            result.setMessage("保存成功");
            return result;
        } catch (Exception e) {
            log.error("OnlCgformApiController.formAddForDesigner()发生异常：" + e.getMessage(), e);
            return Result.error("保存失败");
        }
    }

    @PutMapping({"/crazyForm/{name}"})
    public Result<?> mo319c(@PathVariable("name") String str, @RequestBody JSONObject jSONObject) {
        try {
            jSONObject.remove("create_by");
            jSONObject.remove("create_time");
            jSONObject.remove("update_by");
            jSONObject.remove("update_time");
            this.onlCgformHeadService.editCrazyFormData(str, jSONObject);
            return Result.ok("保存成功!");
        } catch (Exception e) {
            log.error("OnlCgformApiController.formEditForDesigner()发生异常：" + e.getMessage(), e);
            return Result.error("保存失败");
        }
    }

@AutoLog(module = com.data.common.constant.enums.ModuleType.ONLINE, operateType = 1, value = "online列表加载")
    @GetMapping({"/getErpColumns/{code}"})
public com.data.common.api.vo.Result<java.util.Map<java.lang.String, java.lang.Object>> mo318c(@PathVariable("code") java.lang.String r13) {
        /*
        // Method dump skipped, instructions count: 174
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.mo318c(java.lang.String):com.data.common.api.vo.Result");
    }

    @AutoLog(module = ModuleType.ONLINE, operateType = 1, value = "online表单加载")
    @GetMapping({"/getErpFormItem/{code}"})
    public Result<com.alibaba.fastjson.JSONObject> mo325e(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            Result.error("表不存在");
        }

        JSONObject rs = CgformUtil.m263b(this.onlineService.queryOnlineFormObj(onlCgformHead, ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername()));

        Result<com.alibaba.fastjson.JSONObject> result = new Result<>();
        result.setResult(rs);
        result.setOnlTable(onlCgformHead.getTableName());

        return result;
    }

    @GetMapping({"/querySelectOptions"})
    public Result<List<com.data.modules.online.cgform.model.TreeModel>> mo307a(@ModelAttribute LinkDown aVar) {
        Result<List<com.data.modules.online.cgform.model.TreeModel>> result = new Result<>();
        result.setResult(this.onlCgformFieldService.queryDataListByLinkDown(aVar));
        result.setSuccess(true);
        return result;
    }

@GetMapping({"/data/{tableName}/queryById"})
public com.alibaba.fastjson.JSONObject mo299a(@PathVariable("tableName") java.lang.String r5, @RequestParam(name = "id") java.lang.String r6, javax.servlet.http.HttpServletRequest r7) {
        /*
        // Method dump skipped, instructions count: 132
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.cgform.p008c.OnlCgformApiController.mo299a(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest):com.alibaba.fastjson.JSONObject");
    }


    //public Result<?> importXls2(@PathVariable("code") String var1, HttpServletRequest var2, HttpServletResponse var3) {
    public Result<?> importXls2( String var1 ,String validateStatus,String isSingleTableImport,String foreignKeys,List<MultipartFile> multipartFiles)  {
        long var4 = System.currentTimeMillis();
        Result var6 = new Result();
        String var7 = "";
        String var8 = validateStatus;
        StringBuffer var9 = new StringBuffer();

        try {
            OnlCgformHead var10 = (OnlCgformHead)this.onlCgformHeadService.getById(var1);
            if (var10 == null) {
                return Result.error("数据库不存在该表记录");
            }

            LambdaQueryWrapper<OnlCgformField> var11 = new LambdaQueryWrapper<OnlCgformField>();
            var11.eq(OnlCgformField::getCgformHeadId, var1);
            List var12 = this.onlCgformFieldService.list(var11);
            String var13 = isSingleTableImport;
            List var14 = CgformUtil.m284e(var12);
            if (ConvertUtils.isEmpty(var13) && var10.getTableType() == 2 && ConvertUtils.isNotEmpty(var10.getSubTableStr())) {
                String[] var15 = var10.getSubTableStr().split(",");
                int var16 = var15.length;

                for(int var17 = 0; var17 < var16; ++var17) {
                    String var18 = var15[var17];
                    OnlCgformHead var19 = (OnlCgformHead)this.onlCgformHeadService.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var18));
                    if (var19 != null) {
                        List var20 = this.onlCgformFieldService.list((Wrapper)(new LambdaQueryWrapper<OnlCgformField>()).eq(OnlCgformField::getCgformHeadId, var19.getId()));
                        List var21 = CgformUtil.m268b(var20, var19.getTableTxt());
                        if (var21.size() > 0) {
                            var14.addAll(var21);
                        }
                    }
                }
            }

            JSONObject var49 = null;
            String var50 = foreignKeys;
            if (ConvertUtils.isNotEmpty(var50)) {
                var49 = JSONObject.parseObject(var50);
            }

            DataSource var53 = (DataSource) SpringContextUtils.getApplicationContext().getBean(DataSource.class);
            String var54 = DbTableUtil.m432a(var53);

            Iterator var55 = multipartFiles.iterator();

            while(true) {
                while(var55.hasNext()) {
                    Object next = var55.next();
                    MultipartFile var23 = (MultipartFile)next;
                    ImportParams var24 = new ImportParams();
                    var24.setImageList(var14);
                    var24.setDataHanlder(new CgFormExcelHandler(var12, this.upLoadPath, this.uploadType));
                    List var25 = ExcelImportUtil.importExcel(var23.getInputStream(), Map.class, var24);
                    if (var25 != null) {
                        Object var26 = "";
                        ArrayList var27 = new ArrayList();

                        Map var29;
                        for(Iterator var28 = var25.iterator(); var28.hasNext(); var29.put("$mainTable$id", var26)) {
                            var29 = (Map)var28.next();
                            boolean var30 = false;
                            Set var31 = var29.keySet();
                            HashMap var32 = new HashMap();
                            Iterator var33 = var31.iterator();

                            String var34;
                            while(var33.hasNext()) {
                                var34 = (String)var33.next();
                                if (var34.indexOf("$subTable$") == -1) {
                                    if (var34.indexOf("$mainTable$") != -1 && ConvertUtils.isNotEmpty(var29.get(var34).toString())) {
                                        var30 = true;
                                        var26 = this.mo300a(var10, var53, var54);
                                    }

                                    var32.put(var34.replace("$mainTable$", ""), var29.get(var34));
                                }
                            }

                            if (var30) {
                                var32.put("id", var26);
                                var27.add(var32);
                                var26 = var32.get("id");
                            }

                            if (var49 != null) {
                                var33 = var49.keySet().iterator();

                                while(var33.hasNext()) {
                                    var34 = (String)var33.next();
                                    System.out.println(var34 + "=" + var49.getString(var34));
                                    var32.put(var34, var49.getString(var34));
                                }
                            }
                        }

                        if (var27 == null || var27.size() == 0) {
                            var6.setSuccess(false);
                            var6.setMessage("导入失败，匹配的数据条数为零!");
                            return var6;
                        }

                        if ("1".equals(var8)) {
                            Map var57 = this.onlCgformSqlService.saveOnlineImportDataWithValidate(var10, var12, var27);
                            String var59 = (String)var57.get("error");
                            var7 = (String)var57.get("tip");
                            if (var59 != null && var59.length() > 0) {
                                var9.append(var10.getTableTxt() + "导入校验," + var7 + ",详情如下:\r\n" + var59);
                            }
                        } else {
                            this.onlCgformSqlService.saveBatchOnlineTable(var10, var12, var27);
                        }

                        if (ConvertUtils.isEmpty(var13) && var10.getTableType() == 2 && ConvertUtils.isNotEmpty(var10.getSubTableStr())) {
                            String[] var58 = var10.getSubTableStr().split(",");
                            int var60 = var58.length;

                            for(int var61 = 0; var61 < var60; ++var61) {
                                String var62 = var58[var61];
                                OnlCgformHead var63 = (OnlCgformHead)this.onlCgformHeadService.getOne((Wrapper)(new LambdaQueryWrapper<OnlCgformHead>()).eq(OnlCgformHead::getTableName, var62));
                                if (var63 != null) {
                                    LambdaQueryWrapper<OnlCgformField> var64 = new LambdaQueryWrapper<OnlCgformField>();
                                    var64.eq(OnlCgformField::getCgformHeadId, var63.getId());
                                    List var65 = this.onlCgformFieldService.list(var64);
                                    ArrayList var35 = new ArrayList();
                                    String var36 = var63.getTableTxt();
                                    Iterator var37 = var25.iterator();

                                    while(var37.hasNext()) {
                                        Map var38 = (Map)var37.next();
                                        boolean var39 = false;
                                        HashMap var40 = new HashMap();
                                        Iterator var41 = var65.iterator();

                                        while(var41.hasNext()) {
                                            OnlCgformField var42 = (OnlCgformField)var41.next();
                                            String var43 = var42.getMainTable();
                                            String var44 = var42.getMainField();
                                            boolean var45 = var10.getTableName().equals(var43) && ConvertUtils.isNotEmpty(var44);
                                            String var46 = var36 + "_" + var42.getDbFieldTxt();
                                            if (var45) {
                                                var40.put(var42.getDbFieldName(), var38.get("$mainTable$" + var44));
                                            }

                                            Object var47 = var38.get("$subTable$" + var46);
                                            if (null != var47 && ConvertUtils.isNotEmpty(var47.toString())) {
                                                var39 = true;
                                                var40.put(var42.getDbFieldName(), var47);
                                            }
                                        }

                                        if (var39) {
                                            var40.put("id", this.mo300a(var63, var53, var54));
                                            var35.add(var40);
                                        }
                                    }

                                    if (var35.size() > 0) {
                                        if ("1".equals(var8)) {
                                            Map var66 = this.onlCgformSqlService.saveOnlineImportDataWithValidate(var63, var65, var35);
                                            String var67 = (String)var66.get("error");
                                            String var68 = (String)var66.get("tip");
                                            if (var67 != null && var67.length() > 0) {
                                                var9.append(var63.getTableTxt() + "导入校验," + var68 + ",详情如下:\r\n" + var67);
                                            }
                                        } else {
                                            this.onlCgformSqlService.saveBatchOnlineTable(var63, var65, var35);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        var7 = "识别模版数据错误";
                        log.error(var7);
                    }
                }

                var6.setSuccess(true);
                if ("1".equals(var8) && var9.length() > 0) {
                    String var56 = CgformUtil.m228a(this.upLoadPath, var10.getTableTxt(), var9);
                    var6.setResult(var56);
                    var6.setMessage(var7);
                    var6.setCode(201);
                } else {
                    var6.setMessage("导入成功!");
                }
                break;
            }
        } catch (Exception var48) {
            var6.setSuccess(false);
            var6.setMessage(var48.getMessage());
            log.error(var48.getMessage(), var48);
        }

        return var6;
    }
}
